package com.xca.znb.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xca.znb.R;
import com.xca.znb.entity.Procurement;

import java.util.List;

public class ProcurementManagerAdapter extends BaseAdapter {
    private Context context ;
    private List<Procurement> pList ;
    public ProcurementManagerAdapter(Context context , List<Procurement> pList){
        this.context = context ;
        this.pList = pList ;
    }
    @Override
    public int getCount() {
        return pList.size();
    }

    @Override
    public Object getItem(int position) {
        return pList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder ;
        if (convertView == null){
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.procurement_manager_list_item , parent , false);
            viewHolder = new ViewHolder();
            viewHolder.prVariety = convertView.findViewById(R.id.procurement_manager_variety);
            viewHolder.prNum = convertView.findViewById(R.id.procurement_manager_num);
            viewHolder.prUnit = convertView.findViewById(R.id.procurement_manager_unit);
            viewHolder.prGetLocal = convertView.findViewById(R.id.procurement_manager_getLocal);
            viewHolder.prId = convertView.findViewById(R.id.procurement_manager_id);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        Procurement procurement = pList.get(position);
        viewHolder.prVariety.setText(procurement.getVariety());
        viewHolder.prNum.setText(procurement.getNeed());
        viewHolder.prUnit.setText(procurement.getUnit());
        viewHolder.prGetLocal.setText(procurement.getDelivery());
        viewHolder.prId.setText(String.valueOf(procurement.getId()));

        viewHolder.prId.setTag(position);
        return convertView;
    }

    static class ViewHolder{
        TextView prVariety ;
        TextView prNum ;
        TextView prUnit ;
        TextView prGetLocal ;
        TextView prId ;
    }
}
